﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Wpf3D
{
    /// <summary>
    /// Interaction logic for GridWindow.xaml
    /// </summary>
    public partial class GridWindow : Window
    {
        private ObservableCollection<Student> studentList = new ObservableCollection<Student>();

        public ObservableCollection<Student> StudentList
        {
            get { return studentList; }
            set { studentList = value; }
        }

        public GridWindow()
        {

            InitializeComponent();

            for (int i = 20; i < 30; i++)
            {
                studentList.Add(new Student { Name = "test" + i.ToString(), Age = i });

            }

            listview.ItemsSource = studentList;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (StudentList.Count > 0)
                StudentList.RemoveAt(0);
        }
    }

    public class ColorConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var item = value as ListViewItem;
            var view = ItemsControl.ItemsControlFromItemContainer(item) as ListView;
            var index = view.ItemContainerGenerator.IndexFromContainer(item);

            if ((view.Items[index] as Student).Age == 22)
            {
                return Brushes.Red;
            }

            if (index % 2 == 0)
            {
                return Brushes.Pink;
            }
            else
            {
                return Brushes.Blue;
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }

    }
}
